#include <iostream>
using namespace std;

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>

int main()
{   
    const char * filename = "test.txt";

    //打开文件
    int fd1 = open(filename,O_RDWR | O_CREAT,0644);
    if(fd1 == -1)
    {
        perror("open error:");
    }
    cout<<"fd1:"<<fd1<<endl;

    //zhangsan
    string name = "zhangsan";

    //往文件里面写内容
    size_t writeBytes = write(fd1,(const void*)name.c_str(),name.size());
    cout <<"writeBytes:"<<writeBytes<<endl;

    close(fd1);
    return 0;
}